package cn.cjxy.springmvcdemo1.controller;

import cn.cjxy.springmvcdemo1.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author huangjie
 * @date 2025/10/13
 */
@Controller//@Responsebody  返回json格式数据 +@Controller
public class ParamController {

    //普通数据接收
    /** 传递参数名称和接收的参数名称一致  可以直接获取
     * 不一致：使用@RequestParam("实际参数名称")，将实参赋值到形参
     * http://localhost:8080/params01?name=admin&age=24
     */
    @RequestMapping("/params01")
    public ModelAndView params01(@RequestParam("name2") String name, Integer age){
        System.out.println("name:"+name);
        System.out.println("age:"+age);

        return null;
    }
    /* 对象接收，如果使用get方式传参，地址栏应该携带和对象中属性所对应的参数名
     * http://localhost:8080/params02?name=admin&age=24&date=2017-05-14
     * 	注意：接收日期必需在 set时间前配置：@DateTimeFormat(pattern="yyyy-MM-dd")
     */
    @RequestMapping("/params02")
    public ModelAndView params02(User user){
        System.out.println("name:"+user.getName());
        System.out.println("age:"+user.getAge());
        System.out.println("date:"+user.getDate());
        return null;
    }
    /**
     * 接收url中参数的请求,接收用户请求参数值
     * http://localhost:8080/params03/delete/100/tom
     * 	注：这种方式为RESTful风格，参数不易过多
     */
    @RequestMapping("/params03/delete/{id}/{username}")
    public ModelAndView params05(@PathVariable("id")Long id,@PathVariable("username")String name){
        System.out.println(id);
        System.out.println(name);
        return null;
    }

    /**
     * 视图解析器
     * @return
     */
    @RequestMapping("/param0")
    public ModelAndView param0(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("jsps");
        return modelAndView;
    }


}
